package com.wyb.controller;

import com.wyb.constant.Result;
import com.wyb.service.UpdateUserServcie;
import com.wyb.utils.JwtUtil;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/updateuser")
public class UpdateUserController {

    @Autowired
    private UpdateUserServcie updateUserServcie;
    @GetMapping("/avatar")
    public Result updateAvatar(@RequestHeader String token, @RequestParam String avatar){
        String userId;
        try {
            Claims claims = JwtUtil.parseJWT(token);
            userId  = claims.getSubject();
        } catch (Exception e) {
      e.printStackTrace();
            throw new RuntimeException("Token不合法");
        }
//        String avatar = user.getAvatar();
        int id = Integer.parseInt(userId);
        return updateUserServcie.updateAvatar(id,avatar);
    }
}
